<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                xmlns:security="http://www.springframework.org/security/tags"
                template="/templates/template.xhtml">
    <ui:define name="title">商务充值</ui:define>
    <ui:define name="content">

        <h:form>
            <p:dialog id="createModal" header="创建" position="center" widgetVar="createPrepaidModal"
                      modal="true" width="600px"
                      rendered="#{security:areAllGranted('LOAN_FAMILY_BACKSTAGE_BUSINESS_PREPAID_ADD')}">
                <p:panelGrid columns="2"
                             columnClasses="ui-grid-col-3,ui-grid-col-9"
                             layout="grid" styleClass="ui-panelgrid-blank"
                             style="border:0px none; background-color:transparent;">
                    <p:outputLabel for="templateIdCreate" value="模板 ID"/>
                    <p:inputText id="templateIdCreate" value="#{businessPrepaidBean.$.modelId}" style="width:100%"/>
                    <p:outputLabel for="partnerNameCreate" value="合作方名"/>
                    <p:inputText id="partnerNameCreate" value="#{businessPrepaidBean.$.partnerName}" style="width:100%"/>
                    <p:outputLabel for="clickPriceCreate" value="点击单价"/>
                    <p:inputText id="clickPriceCreate" value="#{businessPrepaidBean.$.amountPerClick}" style="width:100%"/>
                    <p:outputLabel for="firstRechargeCreate" value="首次充值"/>
                    <p:inputText id="firstRechargeCreate" value="#{businessPrepaidBean.$.rechargeBalance}" style="width:100%"/>
                </p:panelGrid>
                <div style="text-align:right;padding-top:20px">
                    <p:commandButton value="确认添加" actionListener="#{businessPrepaidBean.onCreate}"
                                     process="createModal" update="@form" />
                </div>
            </p:dialog>

            <p:dialog id="editModal" header="编辑" position="center" widgetVar="editPrepaidModal"
                      modal="true" width="600px"
                      rendered="#{security:areAllGranted('LOAN_FAMILY_BACKSTAGE_BUSINESS_PREPAID_EDIT')}">
                <p:panelGrid columns="2"
                             columnClasses="ui-grid-col-3,ui-grid-col-9"
                             layout="grid" styleClass="ui-panelgrid-blank"
                             style="border:0px none; background-color:transparent;">
                    <p:outputLabel for="templateIdEdit" value="模板 ID"/>
                    <p:inputText id="templateIdEdit" disabled="true" value="#{businessPrepaidBean.$.modelId}" style="width:100%"/>
                    <p:outputLabel for="partnerNameEdit" value="合作方名"/>
                    <p:inputText id="partnerNameEdit" value="#{businessPrepaidBean.$.partnerName}" style="width:100%"/>
                    <p:outputLabel for="clickPriceEdit" value="点击单价"/>
                    <p:inputText id="clickPriceEdit" value="#{businessPrepaidBean.$.amountPerClick}" style="width:100%"/>
                </p:panelGrid>
                <div style="text-align:right;padding-top:20px">
                    <p:commandButton value="确认修改" actionListener="#{businessPrepaidBean.onEdit}" process="editModal" update="@form"/>
                </div>
            </p:dialog>

            <p:dialog id="rechargeModal" header="充值" position="center" widgetVar="createRechargeModal"
                      modal="true" width="600px"
                      rendered="#{security:areAllGranted('LOAN_FAMILY_BACKSTAGE_BUSINESS_PREPAID_RECHARGE')}">
                <p:panelGrid columns="2"
                             columnClasses="ui-grid-col-3,ui-grid-col-9"
                             layout="grid" styleClass="ui-panelgrid-blank"
                             style="border:0px none; background-color:transparent;">
                    <p:outputLabel for="templateIdRecharge" value="当前余额（元）"/>
                    <p:inputText id="templateIdRecharge" value="#{businessPrepaidBean.$.balance}" disabled="true" style="width:100%"/>
                    <p:outputLabel for="partnerNameRecharge" value="充值金额（元）"/>
                    <p:inputText id="partnerNameRecharge" value="#{businessPrepaidBean.$.rechargeBalance}" style="width:100%"/>
                </p:panelGrid>
                <div style="text-align:right;padding-top:20px">
                    <p:outputLabel value="当前商务充值信息已经被禁用，请先启用" rendered="#{businessPrepaidBean.$.isDisable()}" style="padding-right:10px;"/>
                    <p:commandButton value="确认充值" actionListener="#{businessPrepaidBean.onRecharge}"
                                     disabled="#{businessPrepaidBean.$.isDisable()}"
                                     process="rechargeModal" update="@form"/>
                </div>
            </p:dialog>

            <p:defaultCommand target="search"/>
            <div class="topbar clearfix" style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="left">
                        <p:commandButton value="批量模式"
                                         icon="fa fa-list-ul"
                                         actionListener="#{businessPrepaidBean.changeModeToBatch}"
                                         update="@form"
                                         process="@this"
                                         rendered="#{businessPrepaidBean.isNotBatch()}"/>

                        <p:commandButton value="常规模式" icon="fa fa-file"
                                         actionListener="#{businessPrepaidBean.changeModeToNormal}"
                                         process="@this"
                                         update="@form"
                                         rendered="#{businessPrepaidBean.isBatch()}"/>

                        <p:commandButton id="toggler" type="button" value="展示选择"
                                         style="width: auto;"
                                         icon="ui-icon-calculator"/>

                        <p:columnToggler datasource="prepaidDataTable" trigger="toggler"/>
                    </f:facet>
                    <f:facet name="right">
                        <p:commandButton id="search" value="查询" icon="fa fa-search"
                                         rendered="#{businessPrepaidBean.isNormal()}"
                                         update="@form"/>
                        <p:commandButton value="禁用" icon="fa fa-times"
                                         rendered="#{businessPrepaidBean.isBatch()}"
                                         actionListener="#{businessPrepaidBean.onBatchDisable()}"
                                         update="@form"/>
                        <p:commandButton value="启用" icon="fa fa-check"
                                         rendered="#{businessPrepaidBean.isBatch()}"
                                         actionListener="#{businessPrepaidBean.onBatchEnable()}"
                                         update="@form"/>
                        <p:commandButton value="重置" icon="fa fa-refresh"
                                         rendered="#{businessPrepaidBean.isNormal()}"
                                         actionListener="#{businessPrepaidBean.onReset}"
                                         process="@this" update="@form"/>
                        <p:commandButton value="新建" icon="fa fa-plus"
                                         actionListener="#{businessPrepaidBean.onCreateTarget}"
                                         oncomplete="PF('createPrepaidModal').show()"
                                         rendered="#{businessPrepaidBean.isNormal() and security:areAllGranted('LOAN_FAMILY_BACKSTAGE_BUSINESS_PREPAID_ADD')}"
                                         process="@this" update="@form"/>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-fluid" style="padding-top: 30px;">
                <div class="ui-g">
                    <div class="ui-g-12">
                        <div class="card">
                            <h1>查询条件</h1>
                            <p:panelGrid columns="6" layout="grid"
                                         columnClasses="ui-grid-col-1,ui-grid-col-3"
                                         styleClass="ui-panelgrid-blank"
                                         style="border:0px none; background-color:transparent;text-align:center;">

                                <p:outputLabel for="templateIdInput" value="模板ID"/>
                                <p:inputText id="templateIdInput" value="#{businessPrepaidBean.$.modelIdInput}"/>

                                <p:outputLabel for="partnerNameInput" value="合作方名"/>
                                <p:inputText id="partnerNameInput" value="#{businessPrepaidBean.$.partnerNameInput}"/>
                            </p:panelGrid>
                        </div>
                        <div class="card">
                            <p:dataTable id="prepaidDataTable"
                                         style="width: 100%;text-align:center"
                                         var="prepaid"
                                         value="#{businessPrepaidBean.lazyDataModel}"
                                         rows="#{constants:get('ROWS')}"
                                         lazy="true"
                                         paginator="true"
                                         paginatorTemplate="#{constants:get('PAGINATOR_TEMPLATE')}"
                                         rowsPerPageTemplate="#{constants:get('ROWS_PER_PAGE_TEMPLATE')}"
                                         emptyMessage="#{constants:get('EMPTY_MESSAGE')}"
                                         scrollable="true"
                                         reflow="true"
                                         selection="#{businessPrepaidBean.selectedRecords}"
                                         resizableColumns="true">

                                <p:column headerText="操作" style="width:70px;" rendered="#{businessPrepaidBean.isNotBatch()}">
                                    <p:splitButton icon="fa fa-credit-card"
                                                   actionListener="#{businessPrepaidBean.onRechargeTarget(prepaid)}"
                                                   oncomplete="PF('createRechargeModal').show()"
                                                   rendered="#{security:areAllGranted('LOAN_FAMILY_BACKSTAGE_BUSINESS_PREPAID_RECHARGE')}"
                                                   process="@this" update="@form">
                                        <p:menuitem value="编辑" icon="fa fa-pencil-square-o"
                                                    actionListener="#{businessPrepaidBean.onEditTarget(prepaid)}"
                                                    oncomplete="PF('editPrepaidModal').show()"
                                                    disabled="#{prepaid.isDisable()}"
                                                    rendered="#{security:areAllGranted('LOAN_FAMILY_BACKSTAGE_BUSINESS_PREPAID_EDIT')}"
                                                    process="@this" update="@form"/>
                                        <p:menuitem value="禁用" icon="fa fa-times"
                                                    actionListener="#{businessPrepaidBean.onDisable(prepaid.modelId)}"
                                                    rendered="#{prepaid.isEnable() and security:areAllGranted('LOAN_FAMILY_BACKSTAGE_BUSINESS_PREPAID_DELETE')}"
                                                    process="@this" update="@form"/>
                                        <p:menuitem value="启用" icon="fa fa-check"
                                                    actionListener="#{businessPrepaidBean.onEnable(prepaid.modelId)}"
                                                    rendered="#{prepaid.isDisable() and security:areAllGranted('LOAN_FAMILY_BACKSTAGE_BUSINESS_PREPAID_DELETE')}"
                                                    process="@this" update="@form"/>
                                    </p:splitButton>
                                </p:column>
                                <p:column selectionMode="multiple" style="width:16px;text-align:center"
                                          rendered="#{businessPrepaidBean.isBatch()}"/>
                                <p:column headerText="模板ID">
                                    <h:outputText value="#{prepaid.modelId}"/>
                                </p:column>
                                <p:column headerText="合作方名" style="text-align:left;">
                                    <h:outputText value="#{prepaid.partnerName}"/>
                                </p:column>
                                <p:column headerText="点击单价（元）" style="text-align:right;">
                                    <h:outputText value="#{prepaid.amountPerClick}"/>
                                </p:column>
                                <p:column headerText="当前余额（元）" style="text-align:right;">
                                    <h:outputText value="#{prepaid.balance}"/>
                                </p:column>
                                <p:column headerText="状态">
                                    <h:outputText value="#{businessPrepaidBean.statusConvert(prepaid.status)}"/>
                                </p:column>
                                <p:column headerText="操作人">
                                    <h:outputText value="#{prepaid.operatorName}"/>
                                </p:column>
                            </p:dataTable>
                        </div>
                    </div>
                </div>
            </div>
        </h:form>
    </ui:define>
</ui:composition>
